package com.zy.rushjdcloud.task;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

/**
 * @author zy
 * @date 2019-10-4 11:13
 */
@Data
@NoArgsConstructor
public class ScheduledTask {

    /**
     * 需要执行方法的线程
     */
    private Runnable runnable;
    /**
     * 唯一的id用于增删改
     */
    private String taskId;

    /**
     * 定时任务需要执行的方法
     */
    private String method;
    /**
     * 首次执行等待时间
     */
    private long initialDelay;
    /**
     * 间隔时间
     */
    private long delay;


    private TaskParams taskParams;

    public ScheduledTask(String taskId, String method,TaskParams params, long initialDelay, long delay, Object bean) {
        this.taskId = taskId;
        this.method = method;
        this.initialDelay = initialDelay;
        this.delay = delay;
        this.taskParams = params;
        runnable = () -> {
            try {
                Method method1 = bean.getClass().getMethod(method, Map.class);
                method1.invoke(bean, params.getMsg());
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
    }

}
